﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using UIShare;

namespace EFong.Host
{
    public partial class FrmHost : BasicForm
    {
        public FrmHost()
        {
            if (DateTime.Now > new DateTime(2010, 10, 1))
            {
                MsgBox.Error("超过试用的时间!");
                Close();
                return;
            }

            InitializeComponent();

            FormOpener.MainForm = this;

            initDB();
            initHost();
        }

        private void initDB()
        {
            ConnectionString connectionString = ConnectionStringManager.LoadByFile();
            if (connectionString == null) 
            {
                connectionString = FrmDBSetting.SetConnectionString();
                if (connectionString == null) 
                {
                    MsgBox.Error("不设置数据库,不能打开系统.");
                    this.Close();
                }
            }

            ConnectionStringManager.SetConnectionString(connectionString);
        }

        private HostMgt hostMgt = new HostMgt();

        private void initHost()
        {
            hostMgt.Start();
        }

        private void FrmHost_FormClosing(object sender, FormClosingEventArgs e)
        {
            hostMgt.Stop();
        }

        private void barButtonSetDB_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            ConnectionString connectionString = FrmDBSetting.SetConnectionString();
            if (connectionString != null)
            {
                ConnectionStringManager.SetConnectionString(connectionString);
            }
        }
 
    }
}
